package com.htzos.admin.system.controller;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.htzos.admin.system.bean.SystemRoleBase;
import com.htzos.admin.system.service.SystemRoleBaseService;
import com.htzos.common.tool.ExtQueryBean;

@Controller
@RequestMapping("/systemRoleBase")
public class SystemRoleBaseController{

    @Resource
    SystemRoleBaseService systemRoleBaseService;

    @RequestMapping("/list")
    public String list(HttpServletRequest request,SystemRoleBase condition, ExtQueryBean extQuery) {
        if(extQuery.getSize() == null) {
            extQuery.setSize(10);
        }
        if(extQuery.getPageNum() == null) {
            extQuery.setPageNum(1);
        }

        extQuery.setTotal(systemRoleBaseService.systemRoleBaseTotal(condition, extQuery));
        List<SystemRoleBase> list= systemRoleBaseService.systemRoleBaseList(condition, extQuery);
        request.setAttribute("list", list);
        request.setAttribute("condition", condition);
        request.setAttribute("extQuery", extQuery);
        return "admin/system/systemRoleBaseList";
    }

    @RequestMapping("/update")
    public ModelAndView update(HttpServletRequest request, SystemRoleBase systemRoleBase) {
        systemRoleBaseService.systemRoleBaseUpdate(systemRoleBase);
        return new ModelAndView(new RedirectView("list"), "useSession", "1");
//        return list(request, new SystemRoleBase(), new ExtQueryBean());
    }

    @RequestMapping("/updatePage")
    public String updatePage(HttpServletRequest request, Integer id) {
        SystemRoleBase systemRoleBase = systemRoleBaseService.systemRoleBaseGet(id);
        request.setAttribute("systemRoleBase", systemRoleBase);
        return "admin/system/systemRoleBaseUpdate";
    }

    @RequestMapping("/insert")
    public ModelAndView insert(HttpServletRequest request, SystemRoleBase systemRoleBase) {
        systemRoleBaseService.systemRoleBaseInsert(systemRoleBase);
        return new ModelAndView(new RedirectView("list"), "useSession", "1");
//        return list(request, new SystemRoleBase(), new ExtQueryBean());
    }
    @RequestMapping("/addPage")
    public String addPage() {
        return "admin/system/systemRoleBaseAdd";
    }

    @RequestMapping("/delete")
    public ModelAndView delete(HttpServletRequest request, SystemRoleBase systemRoleBase) {
    	systemRoleBase.setRoleId(Integer.valueOf(request.getParameter("id")));
        systemRoleBaseService.systemRoleBaseDelete(systemRoleBase);
        return new ModelAndView(new RedirectView("list"), "useSession", "1");
//        return list(request, new SystemRoleBase(), new ExtQueryBean());
    }
}